<template>
  <div>
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="平台" prop="platform">
        <el-select v-model="queryParams.platform" filterable placeholder="请选择平台" clearable size="small">
          <el-option
            v-for="dict in platformOptions"
            :key="dict.dictValue"
            :label="dict.dictLabel"
            :value="dict.dictValue"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="状态" prop="status">
        <el-select v-model="queryParams.status" placeholder="请选择状态" clearable size="small">
          <el-option label="最新" :value="1" />'
          <el-option label="历史" :value="2" />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="priceLogList" borders>
      <el-table-column label="编号" align="center" type="index" />
      <el-table-column label="商品编号" align="center" prop="goodsId" />
      <el-table-column label="平台" align="center" prop="platform" :formatter="platformFormat" />
      <el-table-column label="价格" align="center" prop="price" />
      <el-table-column label="状态" align="center" prop="status">
        <template v-slot="scope">
          <el-tag type="success" v-if="scope.row.status === 1">最新</el-tag>
          <el-tag type="info" v-else>历史</el-tag>
        </template>
      </el-table-column>
      <el-table-column label="创建人" align="center" prop="createBy" />
      <el-table-column label="创建时间" align="center" prop="createTime" />
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script>
import { listPriceLog } from "@/api/recovery/priceLog";

export default {
  name: "SalePriceList",
  props: {
    propGoodsId: {type: String}
  },
  watch: {
    propGoodsId(now, old) {
      if(now) {
        this.queryParams.goodsId = now;
        this.getList();
      }
    }
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 预售价日志表格数据
      priceLogList: [],
      // 平台字典
      platformOptions: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        goodsId: this.propGoodsId,
        platform: null,
        price: null,
        status: null,
        createId: null,
      }
    };
  },
  created() {
    this.getList();
    this.getDicts("sale_price_log_platform").then(response => {
      this.platformOptions = response.data;
    });
  },
  methods: {
    /** 查询预售价日志列表 */
    getList() {
      this.loading = true;
      listPriceLog(this.queryParams).then(response => {
        this.priceLogList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 平台字典翻译
    platformFormat(row, column) {
      return this.selectDictLabel(this.platformOptions, row.platform);
    },

    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    }
  }
};
</script>
